//
//  BSFooterView.m
//  BS
//
//  Created by lanou on 15/8/15.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "BSFooterView.h"

#import "UMSocial.h"

#import "BSTCommentVC.h"

#import "Header.h"
#import "LJRequestManagerBlock.h"
@interface BSFooterView ()

@property (weak, nonatomic)UIButton *dingButton;

@property (weak, nonatomic)UIButton *caiButton;


@property (weak, nonatomic)UIButton *commentButton;


@end

@implementation BSFooterView

//自定义头试图
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, 50);
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mainCellBottom"]];
        imageView.frame = CGRectMake(-30, 0, SCREEN_WIDTH + 60, 50);
        [self.contentView addSubview:imageView];
        [self addButton:@"0" image:@"mainCellDingN" selectedImage:@"mainCellDingClickN" tag:1001];
        [self addButton:@"0" image:@"mainCellCaiN" selectedImage:@"mainCellCaiClickN" tag:1002];
        [self addButton:@"0" image:@"mainCellShareN" selectedImage:@"mainCellShareClickN" tag:1003];
        [self addButton:@"0" image:@"mainCellCommentN" selectedImage:@"mainCellCommentClickN" tag:1004];
        _dingButton = (UIButton *)[self viewWithTag:1001];
        _caiButton = (UIButton *)[self viewWithTag:1002];
        _shareButton = (UIButton *)[self viewWithTag:1003];
        _commentButton = (UIButton *)[self viewWithTag:1004];
    }
    return self;
}

- (void)addButton:(NSString *)title image:(NSString *)imageName selectedImage:(NSString *)selectedImageName tag:(int)tag{

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:selectedImageName] forState:UIControlStateSelected];
    [button addTarget:self action:@selector(doTapBtn:) forControlEvents:UIControlEventTouchUpInside];
    button.tag = tag;
    [button setBackgroundColor:[UIColor whiteColor]];
     button.frame = CGRectMake((tag - 1001) * (self.frame.size.width / 4.0), 1, self.frame.size.width / 4.0, 40);
    [self.contentView addSubview:button];
}


- (void)doTapBtn:(UIButton *)btn{

    switch (btn.tag) {
            case 1001:
            [self ding:btn];
            break;
            case 1002:
            [self cai:btn];
            break;
            case 1003:
            [self share:btn];
            break;
            case 1004:
            [self comment:btn];
            break;
        default:
            break;
    }
}


- (void)ding:(UIButton *)button{

}


- (void)cai:(UIButton *)button{
}


- (void)share:(UIButton *)button{

    [UMSocialSnsService presentSnsIconSheetView:self.vc
                                         appKey:@"55d8471be0f55a97c2003361"
                                      shareText:self.model.text
                                     shareImage:[UIImage imageNamed:@"AppIcon29x29"]
                                shareToSnsNames:@[UMShareToQQ,UMShareToQzone,UMShareToSina,UMShareToWechatTimeline,UMShareToWechatSession]
                                       delegate:(id)self.vc];

     [UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToQQ,UMShareToQzone,UMShareToWechatSession,UMShareToWechatTimeline]];
    
    [UMSocialData defaultData].extConfig.qqData.url = self.model.weixin_url;
    [UMSocialData defaultData].extConfig.qzoneData.url = self.model.weixin_url;
    [UMSocialData defaultData].extConfig.wechatSessionData.url = self.model.weixin_url;
    [UMSocialData defaultData].extConfig.wechatTimelineData.url = self.model.weixin_url;
    [UMSocialData defaultData].extConfig.wechatSessionData.title = @"分享一条好玩的,点击查看";
    [UMSocialData defaultData].extConfig.wechatTimelineData.title = @"分享一条好玩的,点击查看";
    [UMSocialData defaultData].extConfig.qqData.title = @"分享一条好玩的段子,点击查看";
    [UMSocialData defaultData].extConfig.qzoneData.title = @"分享一条好玩的段子,点击查看";
    [[UMSocialData defaultData].urlResource setResourceType:UMSocialUrlResourceTypeImage url:_model.image_small];
    [[UMSocialData defaultData].urlResource setResourceType:UMSocialUrlResourceTypeMusic url:_model.voiceuri];
    [[UMSocialData defaultData].urlResource setResourceType:UMSocialUrlResourceTypeVideo url:_model.videouri];

    
    

}



- (void)comment:(UIButton *)button{
    
    BSTCommentVC *commentVC = [[BSTCommentVC alloc] init];
    commentVC.data_id = _model.ID;
    [self.nav pushViewController:commentVC animated:YES];
    
}


- (void)setModel:(BSListModel *)model{

    _model = model;
    if([_model.comment isEqualToString:@"0"]){

        _commentButton.userInteractionEnabled = NO;
    }
    else{
     _commentButton.userInteractionEnabled = YES;
    }
    [_dingButton setTitle:_model.ding forState:UIControlStateNormal];
      [_caiButton setTitle:_model.cai forState:UIControlStateNormal];
    [_commentButton setTitle:_model.comment forState:UIControlStateNormal];
    [_shareButton setTitle:_model.repost forState:UIControlStateNormal];
}



@end
